# 1. 注册实例页面,3个表单的注册操作
# 2. 注册页面的select下拉练习
# 3. 注册页面的alter练习
# 4. 登录qq邮箱[选做]
# 5. 登录163邮箱[选做]
# 6. 使用163邮箱发邮件[选做]


from selenium import webdriver
from selenium.webdriver.common.by import By
import os
import time


class Register:
    def __init__(self):
        # 打开浏览器，请求本地
        self.driver = webdriver.Chrome()
        self.driver.get('file:///'+os.path.abspath("html")+'/注册实例.html')

    def Login(self):
        self.user = self.driver.find_element(By.ID,'user')
        time.sleep(2)
        # 输入账号
        self.user.send_keys('123123')
        time.sleep(2)
        # 输入密码
        pw = self.driver.find_element(By.ID,'password')
        pw.send_keys('123456')
        time.sleep(2)
        # 输入手机号
        tel = self.driver.find_element(By.ID, "tel")
        tel.send_keys("11111111111")
        time.sleep(2)
        # 输入邮箱
        email = self.driver.find_element(By.ID,'email')
        email.send_keys('123123@qq.com')
        time.sleep(2)
        btn = self.driver.find_element(By.XPATH,'//*[@id="zc"]/fieldset/button')
        btn.click()
        time.sleep(2)


    def user1(self):
        self.driver.switch_to.frame('idframe1')
        self.driver.find_element(By.ID, "userA")
        # 输入账号
        userA = self.driver.find_element(By.ID, "userA")
        userA.send_keys('123456')
        time.sleep(2)
        # 输入密码
        passwordA = self.driver.find_element(By.ID, "passwordA")
        passwordA.send_keys('123456')
        time.sleep(2)
        # 输入电话
        telA = self.driver.find_element(By.ID, "telA")
        telA.send_keys('12345678912')
        time.sleep(2)
        # 输入邮箱
        emailA = self.driver.find_element(By.ID, "emailA")
        emailA.send_keys('123456@qq.com')
        time.sleep(2)
        btnA = self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button')
        btnA.click()

    def user2(self):
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame('myframe2')
        zcb = self.driver.find_element(By.ID, 'userB')
        userB = self.driver.find_element(By.ID, "userB")
        # 输入账号
        print(userB)
        userB.send_keys('654321')
        time.sleep(2)
        # 输入密码
        passwordB = self.driver.find_element(By.ID, "passwordB")
        passwordB.send_keys('654321')
        time.sleep(2)
        # 输入手机号
        telB = self.driver.find_element(By.ID, "telB")
        telB.send_keys("12345678912")
        time.sleep(2)
        # 输入邮箱
        emailB = self.driver.find_element(By.ID, "emailB")
        emailB.send_keys('654321@qq.com')
        time.sleep(2)
        btnB = self.driver.find_element(By.XPATH, '//*[@id="zc"]/fieldset/button')
        btnB.click()

    def quit(self):
        self.driver.quit()



if __name__ == '__main__':
    register = Register()
    register.Login()
    register.user1()
    register.user2()
    register.quit()
